﻿using System;
using JetBrains.Annotations;
using Missbot.AIModule.Pet;
using Missbot.Common;
using Missbot.Core.Base;

namespace Missbot.AIModule.Vip.VipArmers
{
    [UsedImplicitly]
    public class 风精灵的陈酿 : IVipArmer
    {
        public string Name { get; set; } = "风精灵的陈酿";
        public string Description { get; set; } = "恢复宠物一半的耐力(无法超过耐力上限)，每周限购2次。";
        public int DiamondsNeed { get; set; } = 150;
        public VipArmerLimitInterval LimitInterval { get; set; } = VipArmerLimitInterval.Weekly;
        public int LimitCount { get; set; } = 2;

        private static PetLevelSvc PetLevelSvc => AutofacSvc.Resolve<PetLevelSvc>();

        public bool Purchase(InboxSession session)
        {
            var pet = PetRecordDA.Get(session.User.ID);
            var petLevel = PetLevelSvc[pet.Level];
            var enduranceConsume = PetEnduranceDA.Get(session.User.ID);

            var restoreEndurance = Math.Min(petLevel.Endurance / 2, enduranceConsume.ConsumeTotal);
            enduranceConsume.ConsumeTotal -= restoreEndurance;
            enduranceConsume.Update();

            session.SendBack($"恭喜{pet.Name}恢复了 {restoreEndurance}点耐力！");
            return true;
        }

        public int MaxContains { get; set; }
    }
}